// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import {getParameterByName} from './assets/js/utils.js'
import pingpp from 'pingpp-js'

Vue.config.productionTip = false

import VueResource from 'vue-resource'
import h5Common from './assets/js/h5Common.js'
Vue.use(VueResource);
Vue.http.options.emulateJSON = true;
Vue.http.options.credentials = true;
Vue.http.options.root = 'http://zhedacxz.com/shopping_zhou/php/index.php/PcApi';
import './assets/lib/public.less'

Vue.mixin({
	methods:{
		pingpay(orderInfo, successCb, failCb){
			successCb = successCb || function(){};
			failCb = failCb || function(){};
			let description = {
				type: 4,
				add_scores: orderInfo.point,
				reduce_scores: 0,
				user_id: orderInfo.user_id,
				order_id: orderInfo.order_id,
				order_form_log_id: orderInfo.order_id
			}
			let data = {
				name: 'shopping.sys.goods.pay',
				channel: 'wx_pub',
				amount: Number(orderInfo.price) * 100,
				order_no: orderInfo.type +　orderInfo.user_id + Date.parse(new Date()),
				description: JSON.stringify(description)
			}
			this.$http.post('', data).then((response) => {
				// alert(JSON.stringify(response.body.data))
				if(response.body.code === 1000) {
					var charge = response.body.data.charge;
					//提交成功
					pingpp.createPayment(charge, function(result, err) {
					    // alert('result:' + JSON.stringify(result) + 'err:' + JSON.stringify(err));
					    if (result == "success") {
					    	successCb();
					    	alert('支付成功！您的流量或话费将稍后到账。');
						}
					    else {
					    	// alert(JSON.stringify(err))
					    	// failCb();
					    }
					});
				}
			})
		}
	}
})
// var xhr = new XMLHttpRequest();
// xhr.open('get', 'http://www.hzchuangxiangzhe.cn/index.php/PcApi?name=shopping.sys.openidExist')
// xhr.send();
// xhr.onload = function(){
// 	if(JSON.parse(xhr.response).code !== 1000) {
// 		location.href = 'http://www.hzchuangxiangzhe.cn/index.php/WX_web/WxLogin/index';
// 	}
// }

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App }
})
